<template>
	<view>
		<uni-collapse accordion v-model="value">
			<uni-collapse-item title="已打卡学生名单" name="1">
				<view class="content" v-for="i in completed" :key="i.id">
					<text>{{i.cname}}</text>
					<button type="primary" size="mini" @click="edit(i.id)" class="btn">编辑</button>
				</view>
			</uni-collapse-item>
			<uni-collapse-item title="未打卡学生名单" name="0">
				<view class="content" v-for="i in uncompleted" :key="i.id">
					<text>{{i.cname}}</text>
					<button type="primary" size="mini" @click="edit(i.id)">编辑</button>
				</view>
			</uni-collapse-item>
		</uni-collapse>


		<uni-popup ref="popup" :mask-click="false">
			<view class="ibox">
				<view class="text">
					修改状态
				</view>
				<view class="btn">
					<button type="primary" @click="change">已到</button>
					<button type="warn" @click="change">未到</button>
				</view>
				<button class="not" @click="not">取消</button>

			</view>

		</uni-popup>

	</view>
</template>

<script>
	import server from "@/util/http.js"
	export default {
		data() {
			return {
				fixedId: '',
				value: "0",
			}
		},
		computed: {
			completed() {
				return this.$store.getters.completed
			},
			uncompleted() {
				return this.$store.getters.uncompleted
			}
		},
		methods: {
			edit(e) {
				this.fixedId = e;
				this.$refs.popup.open('center');

			},
			not() {
				this.$refs.popup.close();
			},
			change() {
				this.$store.commit('change', this.fixedId);
				uni.showToast({
					title: '修改成功',
					duration: 1000
				});
				setTimeout(() => {
					uni.hideToast();
					this.$refs.popup.close();
				}, 1000)
			},
			request() {
				server({
					url: `http://127.0.0.1:4523/mock/906666/signDetail`,
					method: 'get',
					success: res => {
						console.log(res);
					},
					fail: e => {
						console.log(e);
					}
				});
			}
		},
		onPullDownRefresh() {
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000)
			this.request();
		},
		onLoad() {
			this.request();
		}
	}
</script>

<style scoped>
	.content {
		display: flex;
		width: 90%;
		margin: 0 auto;
		font-size: 18px;
		padding: 5px 5px;
		flex-direction: row;
		justify-content: space-around;
		align-items: center;
	}

	.ibox {
		background-color: white;
		font-size: 40rpx;
		border-radius: 6px;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
	}

	>>>.uni-popup .uni-popup__wrapper {
		width: 70%;
	}

	.text {
		text-align: center;
	}

	.btn {
		display: flex;
	}

	.btn button {
		width: 40%;
		margin-top: 10px;
	}

	.not {
		margin-top: 10px;
		width: 90%;
	}

	>>>uni-text {
		flex: 2;
	}

	>>>.uni-collapse-item__title-text {
		font-size: 16px;
	}
</style>
